<!DOCTYPE html>


<html>
	<head>
		<meta charset="utf-8" />
		<title>PutMessage</title>
	</head>

	<body>
		<?php
            session_start();

			if(isset($_GET['idSuj']))
				{
					$idSuj = $_GET['idSuj'];
				}
			else 
				{
					?>
					<script type="text/javascript">
						document.location.href="index.php";
					</script>					
					
					<?php
				}
            date_default_timezone_set('Europe/Paris');
			$requete = "INSERT INTO message (id_sujet, id, titre_message, contenu_message, date_message) VALUES ('" . $idSuj . "','" . $_SESSION['idUser'] . "', '" . $_POST['titre'] . "', '" . $_POST['message'] . "','" . date("Y-m-d") . "');";
			
			$mysqli = new mysqli("localhost", "root", "root", "forum");
			
			/* Vérification de la connexion */
			if (mysqli_connect_errno())
				{
    				echo 'Échec de la connexion : ' . mysqli_error();
    				exit;
				}

			if ($response = $mysqli->query($requete))
				{
						echo '<script type="text/javascript">
							document.location.href="affPost.php?page=1&idSuj=' . $idSuj . '";
						</script>';
				}
			else 
				{
						echo '<script type="text/javascript">
							document.location.href="index.php";
						</script>';				
					
				}
		?>
	</body>
</html>